package com.acme.bankapp.domain.bank;

public class CheckingAccount extends AbstractAccount {

	private double overdraft;

	public CheckingAccount(final double amount, final double overdraft) {
		super(amount);
		this.overdraft = overdraft;
	}
	
	public CheckingAccount(final double amount){
		this (amount,0.0);
	}

	@Override
	public void withdraw(double amount) {
		if (amount <= (balance+overdraft)) {
			balance -= amount;
		} else {
			System.out.println("Error: withdraw failed");
		}
	};
	
	public int hashCode() {
		return super.hashCode()*31 + 1237;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CheckingAccount other = (CheckingAccount) obj;
		if (Double.doubleToLongBits(balance) != Double
				.doubleToLongBits(other.balance))
			return false;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public double getMaximumAmountToWithdraw() {
		return (balance+overdraft);		
	}

	@Override
	public String toString() {
		return "Checking "+ super.toString() + " ";
	}
	
	
}

